package com.example.demo.controller;

import com.example.demo.utils.MailSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EmailController {

    @Autowired
    private MailSender mailSender;

    @GetMapping("/sendEmail")
    public String sendEmail() {
        String sender = "default@example.com";
        String to = "recipient_email@example.com";
        String subject = "Test Email";
        String text = "This is a test email sent from Spring Boot.";

        try {
            mailSender.sendSimpleEmail(sender, to, subject, text);
            return "Email sent successfully!";
        } catch (Exception e) {
            return "Failed to send email: " + e.getMessage();
        }
    }
}